s = "PAYPALISHIRING", numRows = 4
// 输出："PINALSIGYAHRPI"
// 解释：
// P     I    N
// A   L S  I G
// Y A   H R
// P     I

var convert = function (s, numRows) {
    if (numRows === 1) return s

    let result = Array.from({ length: numRows }, () => []);
    let i = 0
    let flag = false
    for (let char of s) {
        result[i].push(char)

        if (i === 0 || i === numRows - 1) {
            flag = !flag
        }

        i += flag ? 1 : -1
    }
    return result.map((item) => {
        return item.join('')
    }).join('')
};
console.log(convert(s, numRows));
